window.onload = function () {
  let swiper = new Swiper("#swiper-container", {
    pagination: ".swiper-pagination",
    paginationClickable: true,
    spaceBetween: 30,
    centeredSlides: true,
    autoplay: 4000,
    autoplayDisableOnInteraction: false,
  });
};
// 时间日期
function addzero(num) {
  if (num >= 10) {
    return "" + num;
  } else {
    return "0" + num;
  }
}
function times() {
  var date = new Date();
  var aTime = document.getElementById("aTime");
  var str =
    addzero(date.getHours()) +
    ":" +
    addzero(date.getMinutes()) +
    ":" +
    addzero(date.getSeconds());
  // aTime.innerHTML = str;
}
setInterval(times, 1000);
times();

// 星期
function Adate() {
  var date = new Date();
  var aDate = document.getElementById("aDate");
  var week = document.getElementById("week");
  var weekList = [
    "星期天",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六",
  ];
  var str =
    date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日";
  aDate.innerHTML = str;
  var westr = weekList[date.getDay()];
  week.innerHTML = westr;
}
Adate();
// 轮播图
trList = ["leftUp", "moveRight", "moveDown", "centerBig", "rightDownBig"];
let swipercontainer_1 = new Swiper(".swiper-container_1", {
  speed: 700,
  autoplay: 5000,
  loop: true,
  autoplayDisableOnInteraction: false,
  effect: "fade",
  pagination: ".swiper-pagination",
  paginationClickable: true,
  onSlideChangeStart: function (swiper) {
    nextSlide = swiper.slides.eq(swiper.activeIndex);
    nextSlide.addClass(trList[Math.floor(Math.random() * 5)]);
  },
  onSlideChangeEnd: function (swiper) {
    prevSlide = swiper.slides[swiper.previousIndex];
    prevSlide.className = "swiper-slide";
  },
});

let swipercontainer_2 = new Swiper(".swiper-container_2", {
  spaceBetween: 20,
  loop: true,
  slidesPerView: "auto",
  speed: 500,
  autoplay: 3000,
});
// 返回顶部
$(function () {
  $(".gotop").hide();
  $(window).bind("scroll", function () {
    if ($(window).scrollTop() <= 100) {
      $(".gotop").hide();
    } else {
      $(".gotop").show();
    }
  });
  $(".gotop").bind("click", function () {
    $("html, body").animate({ scrollTop: 0 }, 300);
  });
  $.ajax({
    //请求方式
    type : "GET",
    //请求的媒体类型
    contentType: "application/json;charset=UTF-8",
    //请求地址
    url : "http://192.168.100.128:10022/journalism/rotationChart",
    //数据，json字符串
    success : function(res){
        console.log(res);
        var dataList = res.data.list
        for (var i = 0; i<dataList.length; i++){
          var text = '<li><a href="/page/journalismInfo?id='+ dataList[i].id+'&catid='+ dataList[i].catid+'" class="clearfix">'+
          '<img src="./static/images/line.png" class="fl mt-2" />'+
          '<span class="fl">'+ dataList[i].title+'</span>'+
          '</a></li>'
          var newsImg = '<div class="swiper-slide cursor-pointer">'+
          '<img src="'+dataList[i].cover+'" />'+
          '</div>'
          $('#newsList').append(text)
          $('#newsImg').append(newsImg)
        } 
    },
    //请求失败，包含具体的错误信息
    error : function(e){
    }
  });
  $('.navConUl li .firstNav').click(function () {
    var _this = this;
    $('.navConUl li .firstNav').each(function () {
        this.className = this == _this ? 'active' : 'none'
    });
  });
});
